home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / amiga / bmake15.lzh / guimain.c < prev    next >
C/C++ Source or Header  |  1991-08-17  |  5KB  |  258 lines

  1. /*    guimain.c
  2.  *    (c) Copyright 1991 by Ben Eng, All Rights Reserved
  3.  *
  4.  */
  5.  
  6. #include <ctype.h>
  7.  
  8. #include <exec/exec.h>
  9. #include <exec/execbase.h>
  10.  
  11. #include <intuition/intuitionbase.h>
  12. #include <graphics/gfxbase.h>
  13.  
  14. #include <clib/exec_protos.h>
  15. #include <clib/dos_protos.h>
  16.  
  17. extern struct GfxBase *GfxBase;
  18. extern struct IntuitionBase *IntuitionBase;
  19.  
  20. #include "make.h"
  21. #include "depend.h"
  22.  
  23. /* Globals */
  24. struct globals Global = {
  25.     NULL,    /* me */
  26.     NULL,    /* logfile */
  27.     NULL,    /* screen */
  28.     NULL,    /* window */
  29.     NULL,    /* drinfo */
  30.  
  31.     {
  32.     (struct Node *)&Global.targetlist.lh_Tail,    /* lh_Head */
  33.     (struct Node *)NULL,                        /* lh_Tail */
  34.     (struct Node *)&Global.targetlist.lh_Head,    /* lh_TailPred */
  35.     (UBYTE)NT_USER,
  36.     (UBYTE)0
  37.     },    /* targetlist */
  38.     {
  39.     (struct Node *)&Global.speciallist.lh_Tail,    /* lh_Head */
  40.     (struct Node *)NULL,                        /* lh_Tail */
  41.     (struct Node *)&Global.speciallist.lh_Head,    /* lh_TailPred */
  42.     (UBYTE)NT_USER,
  43.     (UBYTE)0
  44.     },    /* speciallist */
  45.     {
  46.     (struct Node *)&Global.patternlist.lh_Tail,    /* lh_Head */
  47.     (struct Node *)NULL,                        /* lh_Tail */
  48.     (struct Node *)&Global.patternlist.lh_Head,    /* lh_TailPred */
  49.     (UBYTE)NT_USER,
  50.     (UBYTE)0
  51.     },    /* patternlist */
  52.     {
  53.     (struct Node *)&Global.macrolist.lh_Tail,    /* lh_Head */
  54.     (struct Node *)NULL,                        /* lh_Tail */
  55.     (struct Node *)&Global.macrolist.lh_Head,    /* lh_TailPred */
  56.     (UBYTE)NT_USER,
  57.     (UBYTE)0
  58.     },    /* macrolist */
  59.     0,    /* builtin flag */
  60.     0,    /* recursion level */
  61.     0L    /* oldcwd */
  62. };
  63.  
  64. static int
  65. open_libraries( void )
  66. {
  67. #ifndef _DCC
  68.     if( !( IntuitionBase = OpenLibrary( "intuition.library", 33 ))) {
  69.         return( 1 );
  70.     }
  71.     if( !( GfxBase = OpenLibrary( "graphics.library", 33 ))) {
  72.         return( 1 );
  73.     }
  74. #endif
  75.     return( 0 );
  76. }
  77.  
  78. static void
  79. close_libraries( void )
  80. {
  81. #ifndef _DCC
  82.     if( IntuitionBase )
  83.         CloseLibrary( IntuitionBase );
  84.  
  85.     if( GfxBase )
  86.         CloseLibrary( GfxBase );
  87. #endif
  88. }
  89.  
  90. static int
  91. new_globals( struct globals *globptr )
  92. {
  93.     static struct TagItem wintags[] = {
  94.         WA_Title, version_string + 7,
  95.         WA_Height, 100L,
  96.         WA_Width, 400L,
  97.         WA_Flags, WFLG_DEPTHGADGET | WFLG_DRAGBAR | WFLG_CLOSEGADGET,
  98.         WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_GADGETUP,
  99.         TAG_END, 0L
  100.     };
  101.  
  102.     globptr->me = (struct Process *) FindTask( NULL ); /* find this task */
  103.     if( !( globptr->screen = LockPubScreen( NULL )))
  104.         goto death;
  105.     if( !( globptr->drinfo = GetScreenDrawInfo( globptr->screen )))
  106.         goto death;    
  107.     if( !( globptr->window = OpenWindowTagList( NULL, wintags )))
  108.         goto death;
  109.  
  110.     return( 0 );
  111. death:
  112.     printf( "problem initializing globals\n" );
  113.     return( 1 );
  114. }
  115.  
  116. static int
  117. delete_globals( struct globals *globptr )
  118. {
  119.     if( Global.oldcwd ) {
  120.         UnLock( CurrentDir( Global.oldcwd ));
  121.     }
  122.  
  123.     memset( globptr, 0, sizeof(struct globals));
  124.  
  125.     /*    just allow exit() to take care of free()ing all of our
  126.      *    allocations, because I don't feel like doing it right now
  127.      */
  128.     NewList( &globptr->targetlist );
  129.     NewList( &globptr->speciallist );
  130.     NewList( &globptr->patternlist );
  131.     NewList( &globptr->macrolist );
  132. }
  133.  
  134.  
  135. static void
  136. die( void )
  137. {
  138.     delete_params();
  139.  
  140.     close_logfile();
  141.  
  142.     delete_globals( &Global );
  143.     close_libraries();
  144. }
  145.  
  146. static int
  147. init( void )
  148. {
  149.     if( open_libraries()) goto death;
  150.     if( new_globals( &Global )) goto death;
  151.  
  152.     /* user interface */
  153.  
  154.     return( 0 );
  155. death:
  156.     return( 1 );
  157. }
  158.  
  159. static long
  160. do_cl_macro( struct string_node *one )
  161. {
  162.     long retval;
  163.     int made;
  164.  
  165.     if( strchr( one->data, '=' )) {
  166.         process_macroline( one->data );
  167.         if( !Global.builtin_flag ) {
  168.             logprintf( "\t%s\n", one->data );
  169.             Remove( &one->node );
  170.             delete_snode( one );
  171.         }
  172.     }
  173.     return( 0 );
  174. }
  175.  
  176. static long
  177. run_one( struct string_node *one )
  178. {
  179.     long retval;
  180.     int made;
  181.  
  182.     debugprintf( 2, ("\n** run_one Make %s **\n", one->data ));
  183.     retval = (long) make_filename( one->data, &made );
  184.     if( !retval && !made ) {
  185.         logprintf( "\"%s\" is up to date\n", one->data );
  186.     }
  187.     return( retval );
  188. }
  189.  
  190. static void
  191. run_it( void )
  192. {
  193.     long retval;
  194.     int made;
  195.  
  196.     if( Param.filelist.lh_Head->ln_Succ )
  197.         (void)for_list( &Param.filelist, do_cl_macro );
  198.     if( Param.filelist.lh_Head->ln_Succ ) {
  199.         (void)for_list( &Param.filelist, run_one );
  200.     }
  201.     else {
  202.         struct target *first_goal;
  203.         for( first_goal = (struct target *)Global.targetlist.lh_Head;
  204.             first_goal->node.ln_Succ;
  205.             first_goal = first_goal->node.ln_Succ ) {
  206.             if( !(first_goal->flags & (TF_PATTERN|TF_BUILTIN ))) break;
  207.         }
  208.         if( first_goal->node.ln_Succ ) {
  209.             debugprintf( 2, ("\n** first_goal Make %s **\n",
  210.                 first_goal->name ));
  211.             retval = make_filename( first_goal->name, &made );
  212.             if( !retval && !made ) {
  213.                 logprintf( "\"%s\" is up to date\n", first_goal->name );
  214.             }
  215.         }
  216.     }
  217.     logprintf( "\tMake done.\n" );
  218. }
  219.  
  220. int
  221. main( int argc, char *argv[] )
  222. {
  223. /*    Allow it to work with limitations on xsystem() and scdir()
  224.     if( GfxBase->LibNode.lib_Version < 36L ) {
  225.         printf( "This program requires Amiga OS 2.0\n" );
  226.         return( 20 );
  227.     }
  228. */
  229.     atexit( die );    /* add die() to normal exit procedure */
  230.  
  231.     if( parse_parameters( argc, argv )) goto bailout;
  232.  
  233.     logprintf( "%s %s\n", version_string+7, verdate_string );
  234.     logprintf( "%s\n", copyright_string );
  235.  
  236.     if( init() ) goto bailout;
  237.     Global.builtin_flag = 1;
  238.     if( init_builtins()) goto bailout;
  239.     if( Param.filelist.lh_Head->ln_Succ )
  240.         (void)for_list( &Param.filelist, do_cl_macro );
  241.     Global.builtin_flag = 0;
  242.  
  243.     if( input_makefile( Param.makefile )) goto bailout;
  244. #if DEBUG
  245.     if( Param.print_database ) dump_all();
  246.     else run_it();
  247. #else
  248.     run_it();
  249. #endif
  250.  
  251.     return( 0 );
  252.  
  253. bailout:
  254.     /* die(); is called by atexit */
  255.     return( 20 );
  256. }
  257.  
  258.